home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
002
/
scann.arc
/
SCAN.C
next >
Wrap
C/C++ Source or Header
|
1986-01-09
|
5KB
|
191 lines
/****************************************************************************/
/* SCAN C source syntax checker */
/****************************************************************************/
#include "stdio.h"
#include "direct.h"
#define MAXL 301
int noc = 0;
int ncc = 0;
char *fgets();
char *strncpy();
char *strchr();
int nq=0;
int ndq=0;
int nb=0;
int nc=0;
int no=0;
main(argc,argv)
int argc;
char *argv[];
{
char fspec[67];
char s[MAXL];
int lno = 0;
int yr;
int mo;
int dy;
int hr;
int mi;
int hrs,mins,secs,tics;
int cur_m;
int cur_d;
int cur_y;
FILE *infile;
FSPEC file_spec;
printf("SCAN C source syntax checker\n");
printf("-------------------------------------------------------------------------------\n");
if(argc > 2)
{
printf("\nInvalid parameter\n");
printf("Syntax: SCAN [d:]filename\n");
printf(" SCAN (for help)\n");
exit(0);
}
if(argc < 2)
{
help();
exit(0);
}
strcpy(fspec,argv[1]);
infile = fopen(fspec,"r");
if(infile == NULL)
{
printf("\nFile not found\n");
printf("Syntax: SCAN [d:]filename\n");
printf(" SCAN (for help)\n");
exit(0);
}
drsfirst(fspec,23,&file_spec); /*read first directory entry for info*/
yr = ((file_spec.fdate >> 9) & 0x7f) + 80;
if(yr >= 100)
yr = yr-100;
mo = (file_spec.fdate >> 5) & 0x0f;
dy = file_spec.fdate & 0x1f;
hr = (file_spec.ftime >> 11) & 0x3f;
if(hr > 12)
hr = hr-12;
mi = (file_spec.ftime >> 5) & 0x3f;
qyretdat(&cur_y,&cur_m,&cur_d); /* return system date */
qyrettim(&hrs,&mins,&secs,&tics); /* return system time */
if(hrs > 12)
hrs = hrs-12;
cur_y = cur_y-1900;
printf("%-12s %7ld %2d/%02d/%02d %2d:%02d Runtime: %2d:%02d %2d/%02d/%d\n",file_spec.fname,file_spec.fsize,mo,dy,yr,hr,mi,hrs,mins,cur_m,cur_d,cur_y);
printf("-------------------------------------------------------------------------------\n\n");
while(fgets(s,MAXL-1,infile) != NULL)
{
lno++;
if(scan_line(s) || (noc != ncc))
{
printf("%5d %s",lno,s);
if(strchr(s,'\n') == NULL)
putchar('\n');
}
}
printf("\nBraces =%4d Single quotes =%4d Double quotes =%4d\n",nb,nq,ndq);
printf("Comment opens =%4d Comment closes =%4d\n\n",no,nc);
}
/*--------------------------------------------------------------------------*/
/* scan_line */
/*--------------------------------------------------------------------------*/
int scan_line(ps)
char *ps;
{
int last_char;
int nquote;
int ndquote;
int nbrace;
last_char = -1;
nbrace = nquote = ndquote = 0;
while(*ps != '\0')
{
switch(*ps)
{
case '/': if(last_char == '*')
{
ncc++;
nc++;
}
break;
case '*': if(last_char == '/')
{
noc++;
no++;
}
break;
case '\'': nquote++;
nq++;
break;
case '\"': ndquote++;
ndq++;
break;
case '{':
case '}': nbrace++;
nb++;
break;
}
last_char = *ps;
ps++;
}
if((nbrace > 0) || ((nquote % 2) != 0) || ((ndquote % 2) != 0))
return(1);
else
return(0);
}
/*--------------------------------------------------------------------------*/
/* help */
/*--------------------------------------------------------------------------*/
help()
{
printf("\nSyntax: SCAN [d:]filename\n\n");
printf("SCAN counts braces, single quotes, double quotes, and opening and closing\n");
printf("comment marks. It prints a line if it has a brace in the line. If an opening\n");
printf("comment mark is alone on a line, that line and every line until a closing mark\n");
printf("is found is printed. Any line that has an odd number of quote marks is also\n");
printf("printed.\n\n");
printf("A total count of opening and closing comment marks, single quotes, double \n");
printf("quotes, and braces is displayed at the end of the listing. Counts for quotes\n");
printf("and braces should be even numbers. Opening comment marks should equal closing\n");
printf("comment marks.\n\n");
printf("SCAN doesn't really find errors, it just reduces the number of lines\n");
printf("which you check.\n\n\n");
}